<%@page contentType="text/html;charset=gbk" import="java.sql.*"%>
<%@ page import = "com.weibo.dao.connDB" %>

<%
connDB db = new connDB();
db.getConnection();
%>

<%!
String result = null;
String nickname = null;
String password = null;

public String login(String name,String password)
{
	connDB db = new connDB();
	db.getConnection();
	try
	{
		db.rs = db.executeQuery("select * from user where nickname = '" + nickname + "'");

		if(!db.rs.next())
		{result = "iddoesnotexist!";}
		
			else if(!db.rs.getString("password").equals(password))
			{result = "passwordfault";}
			
				else{result = "successfullogin!";}

	}
	catch(Exception e){
		
		System.out.println("sql problem");
		e.printStackTrace();
		return null;
	}
return result ;
}
%>

<%
nickname = request.getParameter("nickname");
password = request.getParameter("password");
if(nickname == null || password == null){
/*
use return 
if yse response.sendRedirect too much
*/
response.sendRedirect("index.jsp");
return;
}

String str = login(nickname,password);

if(str.equals("successfullogin!"))
{
	try
	{
		db.rs = db.executeQuery("select * from user where nickname = '" + nickname + "'");
		
		while(db.rs.next())
		{
			String Nickname = db.rs.getString("nickname");
			String Fans=db.rs.getString("fans");
			String Focus=db.rs.getString("focus");
			String nickname = "nickname";
			String focus = "focus";
			String fans ="fans";
			
			
			
			System.out.println(Nickname+Fans+Focus+"loginS.jsp");
%>
        	
        	<form method="post" id="loginInfo" action="home.jsp">
        	<table><tr>
			<input type="hidden" name=<%=nickname%> id=<%=nickname%> value=<%=Nickname%>>
			<input type="hidden" name=<%=fans%> id=<%=fans%> value=<%=Fans%>>
			<input type="hidden" name=<%=focus%> id=<%=focus%> value=<%=Focus%>>
			</tr></table>
			<script language="JavaScript"> 
			document.getElementById("loginInfo").submit();
			</script> 
			</form>
<%
		}
		
	}
	catch(Exception e)
	{
		//System.out.println("33333333333333333333333333333333");
		e.printStackTrace();
	}
		/*set cookies*/
		session.setAttribute("nickname",nickname);
		session.setAttribute("password",password);
		
		/*set cookies*/
		int countIndexOfHome = 0;
		session.setAttribute("countIndexOfHome","0");
		
}
else{
	//alert("wrong name or password.try again");
	
	response.sendRedirect("index.jsp");
	
	return;
}
%>
